

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="python" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="python" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>QUANTAXIS.QASU.save_tdx &mdash; QUANTAXIS 1.0.39 documentation</title>
  

  
  
  
  

  

  
  
    

  

  
    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> QUANTAXIS
          

          
          </a>

          
            
            
              <div class="version">
                1.0.39
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">QUANTAXIS</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>QUANTAXIS.QASU.save_tdx</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for QUANTAXIS.QASU.save_tdx</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding:utf-8</span>
<span class="c1">#</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2016-2018 yutiansut/QUANTAXIS</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in all</span>
<span class="c1"># copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<span class="c1"># SOFTWARE.</span>

<span class="kn">import</span> <span class="nn">concurrent</span>
<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">from</span> <span class="nn">concurrent.futures</span> <span class="k">import</span> <span class="n">ProcessPoolExecutor</span><span class="p">,</span> <span class="n">ThreadPoolExecutor</span>

<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">pymongo</span>

<span class="kn">from</span> <span class="nn">QUANTAXIS.QAFetch</span> <span class="k">import</span> <span class="n">QA_fetch_get_stock_block</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAFetch.QATdx</span> <span class="k">import</span> <span class="p">(</span><span class="n">QA_fetch_get_index_day</span><span class="p">,</span>
                                     <span class="n">QA_fetch_get_index_min</span><span class="p">,</span>
                                     <span class="n">QA_fetch_get_stock_day</span><span class="p">,</span>
                                     <span class="n">QA_fetch_get_stock_info</span><span class="p">,</span>
                                     <span class="n">QA_fetch_get_stock_list</span><span class="p">,</span>
                                     <span class="n">QA_fetch_get_stock_min</span><span class="p">,</span>
                                     <span class="n">QA_fetch_get_stock_transaction</span><span class="p">,</span>
                                     <span class="n">QA_fetch_get_stock_xdxr</span><span class="p">,</span> <span class="n">select_best_ip</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAFetch.QATushare</span> <span class="k">import</span> <span class="n">QA_fetch_get_stock_time_to_market</span>
<span class="kn">from</span> <span class="nn">QUANTAXIS.QAUtil</span> <span class="k">import</span> <span class="p">(</span><span class="n">DATABASE</span><span class="p">,</span> <span class="n">QA_util_get_next_day</span><span class="p">,</span>
                              <span class="n">QA_util_get_real_date</span><span class="p">,</span> <span class="n">QA_util_log_info</span><span class="p">,</span>
                              <span class="n">QA_util_to_json_from_pandas</span><span class="p">,</span> <span class="n">trade_date_sse</span><span class="p">)</span>

<span class="c1"># ip=select_best_ip()</span>


<div class="viewcode-block" id="now_time"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.now_time">[docs]</a><span class="k">def</span> <span class="nf">now_time</span><span class="p">():</span>
    <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">QA_util_get_real_date</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">()</span> <span class="o">-</span> <span class="n">datetime</span><span class="o">.</span><span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">1</span><span class="p">)),</span> <span class="n">trade_date_sse</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span> <span class="o">+</span> \
        <span class="s1">&#39; 17:00:00&#39;</span> <span class="k">if</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">hour</span> <span class="o">&lt;</span> <span class="mi">15</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">QA_util_get_real_date</span><span class="p">(</span>
            <span class="nb">str</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">()),</span> <span class="n">trade_date_sse</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span> <span class="o">+</span> <span class="s1">&#39; 15:00:00&#39;</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_day"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_day">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_day</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_day</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll_stock_day</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_day</span>
    <span class="n">coll_stock_day</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span>
        <span class="p">[(</span><span class="s2">&quot;code&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s2">&quot;date_stamp&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll_stock_day</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;##JOB01 Now Saving STOCK_DAY==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>

            <span class="n">ref</span> <span class="o">=</span> <span class="n">coll_stock_day</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">]})</span>
            <span class="n">end_date</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="c1"># 加入这个判断的原因是因为如果股票是刚上市的 数据库会没有数据 所以会有负索引问题出现</span>

                <span class="n">start_date</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;date&#39;</span><span class="p">]</span>

                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_DAY </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                                 <span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_day</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">QA_util_get_next_day</span><span class="p">(</span><span class="n">start_date</span><span class="p">),</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">)))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">start_date</span> <span class="o">=</span> <span class="s1">&#39;1990-01-01&#39;</span>
                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_DAY </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_day</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">)))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                         <span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">item</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">)</span>
        <span class="p">)</span>
        <span class="n">__saving_work</span><span class="p">(</span><span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">item</span><span class="p">],</span> <span class="n">coll_stock_day</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_week"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_week">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_week</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_week</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll_stock_week</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_week</span>
    <span class="n">coll_stock_week</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span>
        <span class="p">[(</span><span class="s2">&quot;code&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s2">&quot;date_stamp&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll_stock_week</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;##JOB01 Now Saving STOCK_WEEK==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>

            <span class="n">ref</span> <span class="o">=</span> <span class="n">coll_stock_week</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">]})</span>
            <span class="n">end_date</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="c1"># 加入这个判断的原因是因为如果股票是刚上市的 数据库会没有数据 所以会有负索引问题出现</span>

                <span class="n">start_date</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;date&#39;</span><span class="p">]</span>

                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_WEEK </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_week</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">QA_util_get_next_day</span><span class="p">(</span><span class="n">start_date</span><span class="p">),</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">,</span> <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;week&#39;</span><span class="p">)))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">start_date</span> <span class="o">=</span> <span class="s1">&#39;1990-01-01&#39;</span>
                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_WEEK </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_week</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">,</span> <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;week&#39;</span><span class="p">)))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                         <span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">item</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>

        <span class="n">__saving_work</span><span class="p">(</span><span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">item</span><span class="p">],</span> <span class="n">coll_stock_week</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_month"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_month">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_month</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_month</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll_stock_month</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_month</span>
    <span class="n">coll_stock_month</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span>
        <span class="p">[(</span><span class="s2">&quot;code&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s2">&quot;date_stamp&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll_stock_month</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;##JOB01 Now Saving STOCK_MONTH==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>

            <span class="n">ref</span> <span class="o">=</span> <span class="n">coll_stock_month</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">]})</span>
            <span class="n">end_date</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="c1"># 加入这个判断的原因是因为如果股票是刚上市的 数据库会没有数据 所以会有负索引问题出现</span>

                <span class="n">start_date</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;date&#39;</span><span class="p">]</span>

                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_MONTH </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_month</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">QA_util_get_next_day</span><span class="p">(</span><span class="n">start_date</span><span class="p">),</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">,</span> <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;month&#39;</span><span class="p">)))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">start_date</span> <span class="o">=</span> <span class="s1">&#39;1990-01-01&#39;</span>
                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_MONTH </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_month</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">,</span> <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;month&#39;</span><span class="p">)))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                         <span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">item</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">)</span>
        <span class="p">)</span>
        <span class="n">__saving_work</span><span class="p">(</span><span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">item</span><span class="p">],</span> <span class="n">coll_stock_month</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_year"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_year">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_year</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_year</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll_stock_year</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_year</span>
    <span class="n">coll_stock_year</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span>
        <span class="p">[(</span><span class="s2">&quot;code&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s2">&quot;date_stamp&quot;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll_stock_year</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span>
                <span class="s1">&#39;##JOB01 Now Saving STOCK_YEAR==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>

            <span class="n">ref</span> <span class="o">=</span> <span class="n">coll_stock_year</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">]})</span>
            <span class="n">end_date</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="c1"># 加入这个判断的原因是因为如果股票是刚上市的 数据库会没有数据 所以会有负索引问题出现</span>

                <span class="n">start_date</span> <span class="o">=</span> <span class="n">ref</span><span class="p">[</span><span class="n">ref</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;date&#39;</span><span class="p">]</span>

                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_YEAR </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_year</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">QA_util_get_next_day</span><span class="p">(</span><span class="n">start_date</span><span class="p">),</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">,</span> <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;year&#39;</span><span class="p">)))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">start_date</span> <span class="o">=</span> <span class="s1">&#39;1990-01-01&#39;</span>
                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;UPDATE_STOCK_YEAR </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">start_date</span> <span class="o">!=</span> <span class="n">end_date</span><span class="p">:</span>
                    <span class="n">coll_stock_year</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_stock_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_date</span><span class="p">,</span> <span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;00&#39;</span><span class="p">,</span> <span class="n">frequence</span><span class="o">=</span><span class="s1">&#39;year&#39;</span><span class="p">)))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                         <span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">item</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>

        <span class="n">__saving_work</span><span class="p">(</span><span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">item</span><span class="p">],</span> <span class="n">coll_stock_year</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_xdxr"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_xdxr">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_xdxr</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;[summary]</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">client</span><span class="o">.</span><span class="n">drop_collection</span><span class="p">(</span><span class="s1">&#39;stock_xdxr&#39;</span><span class="p">)</span>
    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_xdxr</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">([(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span>
                       <span class="p">(</span><span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll</span><span class="p">):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span>
            <span class="s1">&#39;##JOB02 Now Saving XDXR INFO ==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                    <span class="n">QA_fetch_get_stock_xdxr</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))))</span>

        <span class="k">except</span><span class="p">:</span>

            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i_</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">i_</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">__saving_work</span><span class="p">(</span><span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>

        <span class="n">try_code</span> <span class="o">=</span> <span class="n">err</span>
        <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;Try to get stock xdxr info in erro list! </span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i__</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">try_code</span><span class="p">)):</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i__</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">try_code</span><span class="p">)))</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
                <span class="nb">float</span><span class="p">(</span><span class="n">i__</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">try_code</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
            <span class="n">__saving_work</span><span class="p">(</span><span class="n">try_code</span><span class="p">[</span><span class="n">i__</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_min"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_min">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_min</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_min</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_min</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">([(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;time_stamp&#39;</span><span class="p">,</span>
                                                     <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;date_stamp&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll</span><span class="p">):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span>
            <span class="s1">&#39;##JOB03 Now Saving STOCK_MIN ==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">for</span> <span class="nb">type</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]:</span>
                <span class="n">ref_</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">find</span><span class="p">(</span>
                    <span class="p">{</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">],</span> <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="nb">type</span><span class="p">})</span>
                <span class="n">end_time</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">19</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="n">ref_</span><span class="p">[</span><span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;datetime&#39;</span><span class="p">]</span>

                    <span class="n">QA_util_log_info</span><span class="p">(</span>
                        <span class="s1">&#39;##JOB03.</span><span class="si">{}</span><span class="s1"> Now Saving </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1"> ==</span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">([</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="nb">type</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                        <span class="n">__data</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_min</span><span class="p">(</span>
                            <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">)</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">__data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">__data</span><span class="p">)[</span><span class="mi">1</span><span class="p">::])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="s1">&#39;2015-01-01&#39;</span>
                    <span class="n">QA_util_log_info</span><span class="p">(</span>
                        <span class="s1">&#39;##JOB03.</span><span class="si">{}</span><span class="s1"> Now Saving </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1"> ==</span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">([</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="nb">type</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                        <span class="n">__data</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_min</span><span class="p">(</span>
                            <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">)</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">__data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">__data</span><span class="p">))</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>

            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">code</span><span class="p">)</span>

    <span class="n">executor</span> <span class="o">=</span> <span class="n">ThreadPoolExecutor</span><span class="p">(</span><span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
    <span class="c1">#executor.map((__saving_work, stock_list.index[i_], coll),URLS)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="p">{</span><span class="n">executor</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span>
        <span class="n">__saving_work</span><span class="p">,</span> <span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span> <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">))}</span>
    <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="n">concurrent</span><span class="o">.</span><span class="n">futures</span><span class="o">.</span><span class="n">as_completed</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">count</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">count</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">count</span> <span class="o">=</span> <span class="n">count</span> <span class="o">+</span> <span class="mi">1</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_index_day"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_index_day">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_index_day</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save index_day</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">__index_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_list</span><span class="p">(</span><span class="s1">&#39;index&#39;</span><span class="p">)</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">index_day</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">([(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span>
                       <span class="p">(</span><span class="s1">&#39;date_stamp&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll</span><span class="p">):</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">ref_</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">]})</span>
            <span class="n">end_time</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">start_time</span> <span class="o">=</span> <span class="n">ref_</span><span class="p">[</span><span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;date&#39;</span><span class="p">]</span>

                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;##JOB04 Now Saving INDEX_DAY==== </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>

                <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                    <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_index_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">QA_util_get_next_day</span><span class="p">(</span><span class="n">start_time</span><span class="p">),</span> <span class="n">end_time</span><span class="p">)))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="s1">&#39;1990-01-01&#39;</span>
                    <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;##JOB04 Now Saving INDEX_DAY==== </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                     <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>
                    <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_index_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">)))</span>
                <span class="k">except</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="s1">&#39;2009-01-01&#39;</span>
                    <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;##JOB04 Now Saving INDEX_DAY==== </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                     <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>
                    <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_index_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">)))</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)):</span>
        <span class="c1">#__saving_work(&#39;000001&#39;)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i_</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">i_</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">__saving_work</span><span class="p">(</span><span class="n">__index_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_index_min"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_index_min">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_index_min</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save index_min</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">__index_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_list</span><span class="p">(</span><span class="s1">&#39;index&#39;</span><span class="p">)</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">index_min</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">([(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;time_stamp&#39;</span><span class="p">,</span>
                                                     <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;date_stamp&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll</span><span class="p">):</span>

        <span class="n">QA_util_log_info</span><span class="p">(</span>
            <span class="s1">&#39;##JOB05 Now Saving Index_MIN ==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>
        <span class="k">try</span><span class="p">:</span>

            <span class="k">for</span> <span class="nb">type</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]:</span>
                <span class="n">ref_</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">find</span><span class="p">(</span>
                    <span class="p">{</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">],</span> <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="nb">type</span><span class="p">})</span>
                <span class="n">end_time</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">19</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="n">ref_</span><span class="p">[</span><span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;datetime&#39;</span><span class="p">]</span>

                    <span class="n">QA_util_log_info</span><span class="p">(</span>
                        <span class="s1">&#39;##JOB05.</span><span class="si">{}</span><span class="s1"> Now Saving </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1"> ==</span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">([</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="nb">type</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                        <span class="n">__data</span> <span class="o">=</span> <span class="n">QA_fetch_get_index_min</span><span class="p">(</span>
                            <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">)</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">__data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">__data</span><span class="p">[</span><span class="mi">1</span><span class="p">::]))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="s1">&#39;2015-01-01&#39;</span>
                    <span class="n">QA_util_log_info</span><span class="p">(</span>
                        <span class="s1">&#39;##JOB05.</span><span class="si">{}</span><span class="s1"> Now Saving </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1"> ==</span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">([</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="nb">type</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                        <span class="n">__data</span> <span class="o">=</span> <span class="n">QA_fetch_get_index_min</span><span class="p">(</span>
                            <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">)</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">__data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">__data</span><span class="p">))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">code</span><span class="p">)</span>

    <span class="n">executor</span> <span class="o">=</span> <span class="n">ThreadPoolExecutor</span><span class="p">(</span><span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>

    <span class="n">res</span> <span class="o">=</span> <span class="p">{</span><span class="n">executor</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span>
        <span class="n">__saving_work</span><span class="p">,</span> <span class="n">__index_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span> <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">))}</span>  <span class="c1"># multi index ./.</span>
    <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="n">concurrent</span><span class="o">.</span><span class="n">futures</span><span class="o">.</span><span class="n">as_completed</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">count</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">count</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">count</span> <span class="o">=</span> <span class="n">count</span> <span class="o">+</span> <span class="mi">1</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_etf_day"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_etf_day">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_etf_day</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save etf_day</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">__index_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_list</span><span class="p">(</span><span class="s1">&#39;etf&#39;</span><span class="p">)</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">index_day</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">([(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span>
                       <span class="p">(</span><span class="s1">&#39;date_stamp&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll</span><span class="p">):</span>

        <span class="k">try</span><span class="p">:</span>

            <span class="n">ref_</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">]})</span>
            <span class="n">end_time</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">start_time</span> <span class="o">=</span> <span class="n">ref_</span><span class="p">[</span><span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;date&#39;</span><span class="p">]</span>

                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;##JOB06 Now Saving ETF_DAY==== </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>

                <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                    <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_index_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">QA_util_get_next_day</span><span class="p">(</span><span class="n">start_time</span><span class="p">),</span> <span class="n">end_time</span><span class="p">)))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">start_time</span> <span class="o">=</span> <span class="s1">&#39;1990-01-01&#39;</span>
                <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;##JOB06 Now Saving ETF_DAY==== </span><span class="se">\n</span><span class="s1"> Trying updating </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
                                 <span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>

                <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                    <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                        <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                            <span class="n">QA_fetch_get_index_day</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">)))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)):</span>
        <span class="c1">#__saving_work(&#39;000001&#39;)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i_</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">i_</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">__saving_work</span><span class="p">(</span><span class="n">__index_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_etf_min"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_etf_min">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_etf_min</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save etf_min</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">__index_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_list</span><span class="p">(</span><span class="s1">&#39;etf&#39;</span><span class="p">)</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">index_min</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">([(</span><span class="s1">&#39;code&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;time_stamp&#39;</span><span class="p">,</span>
                                                     <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;date_stamp&#39;</span><span class="p">,</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">ASCENDING</span><span class="p">)])</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll</span><span class="p">):</span>

        <span class="n">QA_util_log_info</span><span class="p">(</span>
            <span class="s1">&#39;##JOB07 Now Saving ETF_MIN ==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>
        <span class="k">try</span><span class="p">:</span>

            <span class="k">for</span> <span class="nb">type</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]:</span>
                <span class="n">ref_</span> <span class="o">=</span> <span class="n">coll</span><span class="o">.</span><span class="n">find</span><span class="p">(</span>
                    <span class="p">{</span><span class="s1">&#39;code&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)[</span><span class="mi">0</span><span class="p">:</span><span class="mi">6</span><span class="p">],</span> <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="nb">type</span><span class="p">})</span>
                <span class="n">end_time</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">19</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="n">ref_</span><span class="p">[</span><span class="n">ref_</span><span class="o">.</span><span class="n">count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="s1">&#39;datetime&#39;</span><span class="p">]</span>

                    <span class="n">QA_util_log_info</span><span class="p">(</span>
                        <span class="s1">&#39;##JOB07.</span><span class="si">{}</span><span class="s1"> Now Saving </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1"> ==</span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">([</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="nb">type</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                        <span class="n">__data</span> <span class="o">=</span> <span class="n">QA_fetch_get_index_min</span><span class="p">(</span>
                            <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">)</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">__data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">__data</span><span class="p">[</span><span class="mi">1</span><span class="p">::]))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">start_time</span> <span class="o">=</span> <span class="s1">&#39;2015-01-01&#39;</span>
                    <span class="n">QA_util_log_info</span><span class="p">(</span>
                        <span class="s1">&#39;##JOB07.</span><span class="si">{}</span><span class="s1"> Now Saving </span><span class="si">{}</span><span class="s1"> from </span><span class="si">{}</span><span class="s1"> to </span><span class="si">{}</span><span class="s1"> ==</span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">([</span><span class="s1">&#39;1min&#39;</span><span class="p">,</span> <span class="s1">&#39;5min&#39;</span><span class="p">,</span> <span class="s1">&#39;15min&#39;</span><span class="p">,</span> <span class="s1">&#39;30min&#39;</span><span class="p">,</span> <span class="s1">&#39;60min&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="nb">type</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">))</span>
                    <span class="k">if</span> <span class="n">start_time</span> <span class="o">!=</span> <span class="n">end_time</span><span class="p">:</span>
                        <span class="n">__data</span> <span class="o">=</span> <span class="n">QA_fetch_get_index_min</span><span class="p">(</span>
                            <span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">,</span> <span class="nb">type</span><span class="p">)</span>
                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">__data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">__data</span><span class="p">))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">code</span><span class="p">)</span>

    <span class="n">executor</span> <span class="o">=</span> <span class="n">ThreadPoolExecutor</span><span class="p">(</span><span class="n">max_workers</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>

    <span class="n">res</span> <span class="o">=</span> <span class="p">{</span><span class="n">executor</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span>
        <span class="n">__saving_work</span><span class="p">,</span> <span class="n">__index_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span> <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">))}</span>  <span class="c1"># multi index ./.</span>
    <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="n">concurrent</span><span class="o">.</span><span class="n">futures</span><span class="o">.</span><span class="n">as_completed</span><span class="p">(</span><span class="n">res</span><span class="p">):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">count</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">count</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">__index_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">count</span> <span class="o">=</span> <span class="n">count</span> <span class="o">+</span> <span class="mi">1</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_list"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_list">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_list</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_list</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">client</span><span class="o">.</span><span class="n">drop_collection</span><span class="p">(</span><span class="s1">&#39;stock_list&#39;</span><span class="p">)</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_list</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">)</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;##JOB08 Now Saving STOCK_LIST ====&#39;</span><span class="p">)</span>
        <span class="n">stock_list_from_tdx</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_list</span><span class="p">()</span>
        <span class="n">pandas_data</span> <span class="o">=</span> <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span><span class="n">stock_list_from_tdx</span><span class="p">)</span>
        <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span><span class="n">pandas_data</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s2">&quot;完成股票列表获取&quot;</span><span class="p">)</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot; Error save_tdx.QA_SU_save_stock_list exception!&quot;</span><span class="p">)</span>
        <span class="k">pass</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_block"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_block">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_block</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_block</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">client</span><span class="o">.</span><span class="n">drop_collection</span><span class="p">(</span><span class="s1">&#39;stock_block&#39;</span><span class="p">)</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_block</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">)</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;##JOB09 Now Saving STOCK_BlOCK ====&#39;</span><span class="p">)</span>
        <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span><span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
            <span class="n">QA_fetch_get_stock_block</span><span class="p">(</span><span class="s1">&#39;tdx&#39;</span><span class="p">)))</span>
        <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span><span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
            <span class="n">QA_fetch_get_stock_block</span><span class="p">(</span><span class="s1">&#39;ths&#39;</span><span class="p">)))</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="k">pass</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_info"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_info">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_info</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_info</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">client</span><span class="o">.</span><span class="n">drop_collection</span><span class="p">(</span><span class="s1">&#39;stock_info&#39;</span><span class="p">)</span>
    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_info</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">)</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">coll</span><span class="p">):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span>
            <span class="s1">&#39;##JOB010 Now Saving STOCK INFO ==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                    <span class="n">QA_fetch_get_stock_info</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))))</span>

        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)):</span>
        <span class="c1">#__saving_work(&#39;000001&#39;)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i_</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">i_</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">__saving_work</span><span class="p">(</span><span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">],</span> <span class="n">coll</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<div class="viewcode-block" id="QA_SU_save_stock_transaction"><a class="viewcode-back" href="../../../source/QUANTAXIS.QASU.html#QUANTAXIS.QASU.save_tdx.QA_SU_save_stock_transaction">[docs]</a><span class="k">def</span> <span class="nf">QA_SU_save_stock_transaction</span><span class="p">(</span><span class="n">client</span><span class="o">=</span><span class="n">DATABASE</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;save stock_transaction</span>

<span class="sd">    Keyword Arguments:</span>
<span class="sd">        client {[type]} -- [description] (default: {DATABASE})</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">stock_list</span> <span class="o">=</span> <span class="n">QA_fetch_get_stock_time_to_market</span><span class="p">()</span>
    <span class="n">coll</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">stock_transaction</span>
    <span class="n">coll</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s1">&#39;code&#39;</span><span class="p">)</span>
    <span class="n">err</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">def</span> <span class="nf">__saving_work</span><span class="p">(</span><span class="n">code</span><span class="p">):</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span>
            <span class="s1">&#39;##JOB10 Now Saving STOCK_TRANSACTION ==== </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">)))</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">coll</span><span class="o">.</span><span class="n">insert_many</span><span class="p">(</span>
                <span class="n">QA_util_to_json_from_pandas</span><span class="p">(</span>
                    <span class="n">QA_fetch_get_stock_transaction</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">stock_list</span><span class="p">[</span><span class="n">code</span><span class="p">]),</span> <span class="nb">str</span><span class="p">(</span><span class="n">now_time</span><span class="p">())[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">])))</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">err</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">code</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)):</span>
        <span class="c1">#__saving_work(&#39;000001&#39;)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;The </span><span class="si">{}</span><span class="s1"> of Total </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i_</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)))</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;DOWNLOAD PROGRESS </span><span class="si">{}</span><span class="s1"> &#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span>
            <span class="nb">float</span><span class="p">(</span><span class="n">i_</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">stock_list</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span><span class="p">))[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;%&#39;</span><span class="p">))</span>
        <span class="n">__saving_work</span><span class="p">(</span><span class="n">stock_list</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">i_</span><span class="p">])</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">err</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39;SUCCESS&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="s1">&#39; ERROR CODE </span><span class="se">\n</span><span class="s1"> &#39;</span><span class="p">)</span>
        <span class="n">QA_util_log_info</span><span class="p">(</span><span class="n">err</span><span class="p">)</span></div>


<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="c1"># QA_SU_save_stock_day()</span>
    <span class="c1"># QA_SU_save_stock_xdxr()</span>
    <span class="c1"># QA_SU_save_stock_min()</span>
    <span class="c1"># QA_SU_save_stock_transaction()</span>
    <span class="c1"># QA_SU_save_index_day()</span>
    <span class="c1"># QA_SU_save_stock_list()</span>
    <span class="c1"># QA_SU_save_index_min()</span>
    <span class="k">pass</span>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, yutiansut.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'1.0.39',
            LANGUAGE:'python',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>